﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ClassLibrary.BLL;

namespace WEB
{
    public partial class Main : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LbSPGH.Text = Session["sohang"].ToString();
                capnhatddlist();
            }
        }
        private void capnhatddlist()
        {
            List<BLLLoaiSP> loai = new List<BLLLoaiSP>();
            loai = new BLLLoaiSP().GetAll();
            DropDownListtimkiemloai.DataSource = loai;
            DropDownListtimkiemloai.DataTextField = "TenLoai";
            DropDownListtimkiemloai.DataValueField = "IDLoai";
            DropDownListtimkiemloai.DataBind();
            DropDownListtimkiemloai.Items.Insert(0, new ListItem("[Chọn loại]", "0"));
            DropDownListtimkiemloai.SelectedIndex = 0;
        }

        protected void BtnTim_Click(object sender, EventArgs e)
        {
            if (input_timkiem.Value == "Tên sản phẩm cần tìm")
            { input_timkiem.Value = ""; }
            if (DropDownListtimkiemloai.SelectedValue.ToString() == "0" && DropDownListtimkiemkhoanggia.SelectedValue.ToString() == "0" && (input_timkiem.Value.Trim().ToString() == ""))
            {
                Labelthongbaotimkiem.Text = "Chọn điều kiện cần tìm";
                return;
            }
            {
                Response.Redirect("KetQuaTimKiem.aspx?tensp=" + input_timkiem.Value.Trim().ToString() + "&idloaisanpham=" + DropDownListtimkiemloai.SelectedValue.ToString() + "&giasp=" + DropDownListtimkiemkhoanggia.SelectedValue.ToString() + "");
            }
        }
    }
}
